package ace.module.oauth2.server.core.impl.authentication.password;

import java.util.Map;
import lombok.Builder;
import lombok.Getter;
import org.springframework.lang.Nullable;
import org.springframework.security.oauth2.core.AuthorizationGrantType;
import org.springframework.security.oauth2.server.authorization.authentication.OAuth2AuthorizationGrantAuthenticationToken;
import org.springframework.security.oauth2.server.authorization.authentication.OAuth2ClientAuthenticationToken;
import org.springframework.security.oauth2.server.authorization.client.RegisteredClient;

/**
 * @author caspar
 * @date 2023/2/8 13:43 密码模式 token
 */
public class Oauth2PasswordAuthenticationToken extends OAuth2AuthorizationGrantAuthenticationToken {

  @Getter private String credentials;
  @Getter private String password;
  @Getter private String username;
  @Getter private RegisteredClient client;

  @Builder
  public Oauth2PasswordAuthenticationToken(
      OAuth2ClientAuthenticationToken clientPrincipal,
      String username,
      String password,
      @Nullable Map<String, Object> additionalParameters) {
    super(AuthorizationGrantType.PASSWORD, clientPrincipal, additionalParameters);
    this.credentials = password;
    this.username = username;
    this.password = password;
    this.client = clientPrincipal.getRegisteredClient();
  }
}
